<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" onload="checkBrowser()">


<section class="content-header">
    <h1 class="pull-left" style="display: inline-block;line-height: 34px;">盘点结果录入</h1>
    <div class="pull-right"
         style="margin:0px 5px 5px 5px;text-align: right">
        <a th:href="@{'/purchase/check/plan/dispatch/adjust/'+${checkPlanModel.cpnId}}"
           shiro:hasPermission="purinv:purcheckadj:edit" id="btn-next" th:if="${checkPlanModel.cpnResStatus==3}"
           class="btn btn-warning">下一步
        </a>
    </div>
    <div class="pull-right"
         style="margin:0px 5px 5px 5px;text-align: right">
        <a href="/purchase/check" shiro:hasPermission="purinv:purcheckplan:view"
           id="btn-return-checkPlanList"
           class="btn btn-info">返回计划列表
        </a>
    </div>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header" style="padding-bottom: 0px">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        计划编号
                                    </label>
                                    <label class="control-label">
                                        <input name="cpnCode" type="text" class="form-control text" maxlength="255"
                                               th:value="${checkPlanModel.cpnCode}" readonly/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        盘点内容
                                    </label>
                                    <label class="control-label">
                                        <input type="text" class="form-control text" th:value="${checkPlanModel.cpnContent}"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlMatProCode" type="text" class="form-control text"
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlMatProName" type="text" class="form-control text"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        物料描述
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlMatDesc" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入物料描述"/>
                                    </label>
                                </div>

                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right;width: 56px;">
                                        区位
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlMatPosition" type="text" class="form-control text"
                                               placeholder="请输入区位"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right;width: 56px;">
                                        仓库
                                    </label>
                                    <label class="control-label">
                                        <select name="cdlMatWhiId" type="text" class="form-control select"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 100px!important;">
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group"
                                     style="margin-right: 10px;margin-bottom: 5px">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <button shiro:hasPermission="purinv:purcheckresult:edit"
                            type="button" id="btn_add_check" class="btn btn-info">
                        新增盘点
                    </button>
                    <a th:href="@{/purchase/check/result/export/{cpnId}(cpnId=${checkPlanModel.cpnId})}"
                       shiro:hasPermission="purinv:purcheckresult:edit"
                       id="btn_downCheckPlan" class="btn btn-primary">
                        导出盘点计划
                    </a>


                    <button id="btn_import_check_result" shiro:hasPermission="purinv:purcheckresult:edit"
                            type="button" class="btn btn-info">
                        导入盘点结果
                    </button>

                    <button shiro:hasPermission="purinv:purcheckresult:edit" id="btn_clean_check_result"
                            type="button" class="btn btn-danger">
                        清空盘点结果
                    </button>

                    <button shiro:hasPermission="purinv:purcheckresult:edit"
                            th:if="${checkPlanModel.cpnResStatus!=3}" id="btn_submit" type="button"
                            class="btn btn-success">提交盘点结果
                    </button>
                    <button shiro:hasPermission="purinv:purcheckresult:edit"
                            th:if="${checkPlanModel.cpnResStatus==3}" id="btn_revoke" type="button"
                            class="btn btn-primary">撤销
                    </button>

                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>

                </div>
            </div>
        </div>
    </div>
</section>
<!--新增盘点模态框-->
<div class="modal fade" id="modal-add-check">
    <div class="modal-dialog" style="width:1000px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增盘点</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                            </div>
                            <div class="box-body">
                                <form id="modalForm" class="form-horizontal" role="form">
                                    <div hidden>
                                        <input type="hidden" name="cdlId"/>
                                        <input type="hidden" name="cpnCode"/>
                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlMatCodeModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    SAP物料编码
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlMatCodeModal" name="cdlMatCode"
                                                           placeholder="请输入SAP物料编码"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px;">
                                                <label class="form-label col-sm-3" for="cdlMatDescModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px ">物料描述</label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;line-height: 35px;width: 120px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlMatDescModal" name="cdlMatDesc"
                                                           placeholder="请输入物料描述"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlNumModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    盘点数量
                                                </label>
                                                <div class="col-sm-3"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           oninput="xyh.inputDecimalThree(this)" maxlength="8"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:100px!important;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlNumModal" name="cdlNum" placeholder="请输入盘点数量"/>
                                                </div>
                                                <label class="form-label col-sm-2" for="cdlUnitModal"
                                                       style="margin: 0px;padding: 0px 12px;line-height: 35px;text-align: right">
                                                    单位
                                                </label>
                                                <div class="col-sm-3"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:100px!important;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlUnitModal" name="cdlUnit" placeholder="请输入单位"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlPriceModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    单价
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           oninput="xyh.inputDecimalThree(this)" maxlength="8"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlPriceModal" name="cdlPrice" placeholder="请输入单价"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlWhiIdModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    仓库
                                                </label>
                                                <div class="col-sm-3" style="margin: 0px;padding: 0px;">
                                                    <select type="text" class="form-control select"
                                                            style="padding: 0px!important;text-align: center!important;text-align-last: center!important;border-width: 1px; border-radius:5px;border-color:#d2d6de;width:100px!important;font-size:12px;"

                                                            id="cdlWhiIdModal" name="cdlWhiId">
                                                    </select>
                                                </div>
                                                <label class="form-label col-sm-2" for="cdlPositionModal"
                                                       style="margin: 0px;padding: 0px 12px;line-height: 35px;text-align: right">
                                                    区位
                                                </label>
                                                <div class="col-sm-3"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:100px!important;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlPositionModal" name="cdlPosition"
                                                           placeholder="请输入区位"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlTrackCodeModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    跟踪号
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlTrackCodeModal" name="cdlTrackCode"
                                                           placeholder="请输入跟踪号"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlProCodeModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    项目编号
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           list="cdlProCodeList"
                                                           autocomplete="off"
                                                           id="cdlProCodeModal" name="cdlProCode"
                                                           oninput="findCdlProCodeListData(this)"
                                                           onchange="changeCdlProName()"
                                                           placeholder="请输入项目编号"/>
                                                    <datalist id="cdlProCodeList">
                                                    </datalist>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlProNameModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    项目名称
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlProNameModal" name="cdlProName"
                                                           placeholder="请输入项目名称"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">

                                    </div>
                                    <div class="row col-md-10 col-md-offset-1">
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlBookkeepingDateModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    记账日期
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" class="form-control datepicker"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                            name="cdlBookkeepingDate"
                                                            id="cdlBookkeepingDateModal"
                                                           placeholder="请输记账日期"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group" style="height: 60px">
                                                <label class="form-label col-sm-3" for="cdlStockTypeModal"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    在库类型
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <select type="text" class="form-control select"
                                                            style="padding: 0px!important;text-align: center!important;text-align-last: center!important;border-width: 1px; border-radius:5px;border-color:#d2d6de;font-size:12px;"
                                                            id="cdlStockTypeModal" name="cdlStockType">
                                                        <option value="">请选择在库类型</option>
                                                        <option value="1">库存在库</option>
                                                        <option value="2">项目在库</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button shiro:hasPermission="purinv:purcheckresult:newplan" type="button" class="btn btn-info"
                        id="btn-save-commit">确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>
<!--盘点模态框-->
<div class="modal fade" id="modal-check">
    <div class="modal-dialog" style="width:500px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">盘点</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                            </div>
                            <div class="box-body">
                                <form id="checkModalForm" class="form-horizontal" role="form">
                                    <div hidden>
                                        <input type="hidden" name="cdlId">
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px;">
                                                <label class="form-label col-sm-3" for="cdlMatDesc"
                                                       style="margin: 0px;padding: 0px;line-height: 35px ">物料描述</label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;line-height: 35px;width: 120px;">
                                                    <input type="text" class="form-control"
                                                           style="border-width: 1px; border-radius:5px;border-color:#d2d6de;width:205px;font-size:12px;height:32px;padding: 6px 12px 6px 12px;text-align: center;vertical-align: middle"
                                                           id="cdlMatDesc" name="cdlMatDesc"
                                                           readonly="readonly"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 160px">
                                                <label class="form-label col-sm-3" for="cdlNum"
                                                       style="margin: 0px;padding: 0px;line-height: 35px">
                                                    盘点数量
                                                </label>
                                                <div class="col-sm-9"
                                                     style="margin: 0px;padding: 0px;">
                                                    <input type="text" id="cdlNum" name="cdlNum"
                                                           oninput="xyh.inputDecimalThree(this)"
                                                           class="form-control" maxlength="9"
                                                           style="width: 200px"
                                                           placeholder="请输入盘点数量">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" shiro:hasPermission="purinv:purcheckresult:edit" class="btn btn-info"
                        id="btn-save-check">确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>
<!--导入模态框-->
<div class="modal fade" id="modal-import">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>上次导入错误数据</label>
                        <a id="download-error"
                           th:data-url="@{/files/{user}/checkError.xls(user=${session.user.account})}"
                           href="javascript:void(0);">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input class="btn" type="file" multiple="multiple" name="file"
                               id="file"
                               accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="purinv:purcheckresult:edit" id="btn-upload" type="button"
                        class="btn btn-info">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;


    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            alert("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }


    /**
     *@FunctionName: findProCodeListData
     *@Description: 根据项目号模糊查询获取项目号列表
     *@Author: 徐一贺
     *@CreateDate: 2020/4/27 14:38
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findCdlProCodeListData(obj) {
        $.post(ctx + 'purchase/change/findProCodeList', {
            code: $(obj).val()
        }, function (result) {
            if (result.type == 'SUCCESS') {
                $("#cdlProCodeList").empty();
                for (var i = 0; i < result.data.length; i++) {
                    $("#cdlProCodeList").append('<option value="' + result.data[i].code + '" data="' + result.data[i].name + '" data-status="' + result.data[i].status + '"></option>');
                }
            }
        }, 'json');
    }

    /**
     *@FunctionName: changeCdlProName
     *@Description: 当项目编号文本框发生改变时，改变项目名称框的内容
     *@Author: 徐一贺
     *@CreateDate: 2020/4/27 14:37
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function changeCdlProName() {
        var input_select = $("#modalForm [name='cdlProCode']").val();
        var option_length = $("#cdlProCodeList").find("option").length;
        for (var i = 0; i < option_length; i++) {
            if (input_select == $("#cdlProCodeList option").eq(i).attr('value')) {
                $("#modalForm [name='cdlProName']").val($("#cdlProCodeList option").eq(i).attr("data"));
                break;
            }
        }
    }

    /**
     *@FunctionName: findWarehouseList
     *@Description: 获取仓库列表
     *@Author: 徐一贺
     *@CreateDate: 2020/3/24 15:31
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findWarehouseList() {
        js.ajax({
            url: ctx + 'common/warehouseInfo/list',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#queryForm [name='cdlMatWhiId']").empty();
                    $("#queryForm [name='cdlMatWhiId']").append('<option value="">全部</option>');
                    $("#modalForm [name='cdlWhiId']").empty();
                    $("#modalForm [name='cdlWhiId']").append('<option value="">全部</option>');
                    for (var i = 0; i < result.data.rows.length; i++) {
                        $("#queryForm [name='cdlMatWhiId']").append('<option value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        $("#modalForm [name='cdlWhiId']").append('<option value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }


    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: 徐一贺
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    $(function () {
        $("title").html($("title").html()+" —— 盘点结果录入");
        findWarehouseList();
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "purchase/check/result/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "cdlId",
            onLoadSuccess: function () {
                $('#bootstrap-table thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#bootstrap-table tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: [
                {
                    title: '序号', field: 'cdlId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '区位', field: 'cdlPosition'},
                {title: '物料描述', field: 'cdlMatDesc'},
                {title: 'SAP物料编码', field: 'cdlMatCode'},
                {title: '项目号', field: 'cdlProCode', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }},
                {title: '项目名称', field: 'cdlProName', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }},
                {title: '当前数量', field: 'cdlItyNum'},
                {title: '单位', field: 'cdlUnit', width: '50'},
                {
                    title: '盘点数量', field: 'cdlNum', formatter: function (value, row, index) {
                        if (value == null || value == undefined) {
                            return "";
                        } else {
                            return value;
                        }
                    }
                },
                {
                    title: '操作', field: 'cpnId', width: '90',
                    formatter: function (value, row, index) {
                        var htmlText = "";
                        if (hasP('purinv:purcheckresult:edit')) {
                            htmlText += '<button class="btn btn-warning btn-xs" onclick="checkOper(' + row.cdlId + ')">盘点</button>';
                        }
                        return htmlText;
                    }
                }
            ]
        });
        formValidator();
        addCheckFormValidator();
        importFormValidator();

        /**
         *新增盘点
         */
        $("#btn_add_check").on('click', function () {
            $("#modalForm")[0].reset();
            $("#modalForm").data('bootstrapValidator').destroy();
            //置空表单验证
            $('#modalForm').data('bootstrapValidator', null);
            //重新绑定表单验证
            addCheckFormValidator();
            js.modal.open("modal-add-check");
        });

        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });
        /**
         * 盘点模态框确认
         */
        $("#btn-save-check").on('click', function () {//销毁表单验证
            $("#checkModalForm").data('bootstrapValidator').destroy();
            //置空表单验证
            $('#checkModalForm').data('bootstrapValidator', null);
            //重新绑定表单验证
            formValidator();

            //验证通过式提交
            js.validSubmit({
                formId: "checkModalForm",
                url: ctx + "purchase/check/result/check",
                data: new FormData($("#checkModalForm")[0]),
                success: function (result) {
                    js.modal.success("盘点成功！");
                    js.table.refresh(table);
                    js.modal.hide("modal-check");
                }
            });
        });
        /** 导入盘点结果计划 */
        $("#btn-upload").click(function () {
            js.validSubmit({
                formId: "importForm",
                url: ctx + "purchase/check/result/import",
                data: new FormData($("#importForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.alert(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-import");
                    }
                }
            });
        });
        /**清空盘点结果*/
        $("#btn_clean_check_result").on('click', function () {
            js.modal.confirm("您确认清空盘点结果吗？", function () {
                $.post(ctx + 'purchase/check/result/clean', {
                    cdlCpnId: [[${checkPlanModel.cpnId}]]
                }, function (result) {
                    if (result.type == 'SUCCESS') {
                        js.table.refresh(table);
                    }
                }, 'json')
            });
        });

        /**提交盘点结果*/
        $("#btn_submit").on("click", function () {
            js.modal.confirm("尊敬的用户，您确认要提交盘点结果吗？", function () {
                $.post(ctx + 'purchase/check/result/submit', {
                    cdlCpnId: [[${checkPlanModel.cpnId}]]
                }, function (result) {
                    if (result.type == 'SUCCESS') {
                        location.href = ctx + "purchase/check";
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }, 'json')
            });
        });
        /**撤销盘点结果*/
        $("#btn_revoke").on("click", function () {
            js.modal.confirm("尊敬的用户，您确认要撤销盘点结果吗？", function () {
                $.post(ctx + 'purchase/check/result/revoke', {
                    cdlCpnId: [[${checkPlanModel.cpnId}]]
                }, function (result) {
                    if (result.type == 'SUCCESS') {
                        location.href = ctx + "purchase/check";
                    }
                    if (result.type == 'ERROR') {
                        js.modal.fail("撤销失败，请先撤销盘点损溢调整。");
                    }
                }, 'json')
            });
        });

        /**导入盘点结果*/
        $("#btn_import_check_result").on('click', function () {
            js.modal.open("modal-import");
        });

        /**
         * 新增盘点模态框确认
         */
        $("#btn-save-commit").on('click', function () {//销毁表单验证
            $("#modalForm").data('bootstrapValidator').destroy();
            //置空表单验证
            $('#modalForm').data('bootstrapValidator', null);
            //重新绑定表单验证
            addCheckFormValidator();
            $("#modalForm [name='cpnCode']").val($("#queryForm [name='cpnCode']").val());
            var intervalNum = 0;
            var intervalId = window.setInterval(function () {
                //验证通过式提交
                js.validSubmit({
                    formId: "modalForm",
                    url: ctx + "purchase/check/result/checkAdd",
                    data: new FormData($("#modalForm")[0]),
                    success: function (result) {
                        js.modal.success("新增盘点成功！");
                        js.table.refresh(table);
                        js.modal.hide("modal-add-check");
                        window.clearInterval(intervalId);
                    }
                });
                intervalNum++;
                if (intervalNum == 30) {
                    window.clearInterval(intervalId);
                }
            }, 500);

        });
        // $("#file").change(function (e) {
        //     xyh.displayExcel($(this),e);
        // })
    });

    /**盘点验证*/
    function formValidator() {
        // 验证初始化
        js.validate.init("checkModalForm", {
            fields: {
                cdlNum: {
                    validators: {
                        notEmpty: {message: '请输入盘点数量'}
                    }
                }
            }
        });
    }


    /**新增盘点验证*/
    function addCheckFormValidator() {
        // 验证初始化
        js.validate.init("modalForm", {
            fields: {
                cdlMatDesc: {
                    validators: {
                        notEmpty: {message: '请输入物料描述'}
                    }
                },
                cdlNum: {
                    validators: {
                        notEmpty: {message: '请输入盘点数量'}
                    }
                },
                cdlUnit: {
                    validators: {
                        notEmpty: {message: '请输入单位'}
                    }
                },
                cdlPrice: {
                    validators: {
                        notEmpty: {message: '请输入单价'}
                    }
                }
                ,
                cdlWhiId: {
                    validators: {
                        notEmpty: {message: '请选择仓库'}
                    }
                }
                ,
                cdlPosition: {
                    validators: {
                        notEmpty: {message: '请输入区位'}
                    }
                },
                cdlBookkeepingDate: {
                    validators: {
                        notEmpty: {message: '请设置记账日期'}
                    }
                },
                cdlStockType: {
                    validators: {
                        notEmpty: {message: '请选择在库类型'}
                    }
                },
                cdlProCode: {
                    validators: {
                        threshold: 6, //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                        callback: {
                            message: "项目号不存在",
                            callback: function (value, validator) {
                                var flag = false;
                                $.ajax({
                                    url: ctx + 'purchase/change/codeExist', // 请求路径
                                    type: 'POST',
                                    async: false,	// 同步请求，必须是false
                                    data: {
                                        ceoNeedProCode: $("#modalForm input[name='cdlProCode']").val() // 请求参数
                                    },
                                    success: function (res) {
                                        flag = $.parseJSON(res).valid;
                                    }
                                });
                                return flag;
                            }
                        }
                    }
                },
            }
        });
    }

    /**上传盘点结果验证*/
    function importFormValidator() {
        // 验证初始化
        js.validate.init("importForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '请选择要上传的文件'}
                    },
                    file: {
                        extension: 'xls,xlsx',
                        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel',
                        message: '请重新选择Excel文件'
                    }
                }
            }
        });
    }

    /**
     *@FunctionName: checkOper
     *@Description: 单调盘点显示模态框
     *@Author: 徐一贺
     *@CreateDate: 2020/4/27 8:20
     *@Phone: 18241927380
     *@Param: [cdlId] 盘点明细主键
     *@Version: 1.0.0
     */
    function checkOper(cdlId) {
        $("#checkModalForm").data('bootstrapValidator').destroy();
        //置空表单验证
        $('#checkModalForm').data('bootstrapValidator', null);
        //重新绑定表单验证
        formValidator("checkModalForm");
        var rowData = $("#bootstrap-table").bootstrapTable('getRowByUniqueId', cdlId);
        $("#checkModalForm").fillData(rowData);
        js.modal.open("modal-check");
    }


</script>
</body>
</html>
